package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    /*
     *向order订单表中添加一条订单数据
     * */
    void insert(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     *
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);

    /**
     * @return 分页按条件查询
     * @author 小陈
     * @DateTime:
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * @return 根据id查询订单
     * @author 小陈
     * @DateTime:
     */
    @Select("select *from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * @return 各个状态的订单数量统计
     * @author 小陈
     * @DateTime:
     */
    @Select("select count(id)from orders where status =#{status}")
    Integer countStatus(Integer confirmed);

    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumber(String outTradeNo);

    /**
     * 根据状态和下单时间查询订单
     *
     * @param status
     * @param orderTime
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> selectByTimeAndStatus(Integer status, LocalDateTime orderTime);

    /*
     * 统计符合条件的营业额
     * */
    Double sumByMap(Map map);

    /*
     * 条件统计订单数量
     *
     * */
    Integer countByMap(Map map);

    /*
     *查询销量排名top10
     * */
    List<GoodsSalesDTO> top10(LocalDate begin, LocalDate end);

    //获取近一个月所有订单
    Integer selectByTimePerioc(LocalDate begin, LocalDate end);
}
